package com.zxl.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;

public class GetWeather {

	public static void main(String args[]){
		URL url = null;
		URLConnection urlconn = null;
		StringBuffer sb = new StringBuffer();
		try {
			url = new URL("http://m.weather.com.cn/data/101010100.html");
			try {
				urlconn = url.openConnection();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpURLConnection httpurlconn = (HttpURLConnection)urlconn;
		
		httpurlconn.setDoOutput(true);
		httpurlconn.setDoInput(true);
		
		httpurlconn.setUseCaches(true);
		
		try {
			httpurlconn.setRequestMethod("GET");
			httpurlconn.setRequestProperty("Content-type", "application/json");
			httpurlconn.connect();
			
			BufferedReader in = new BufferedReader(new InputStreamReader(httpurlconn.getInputStream(),"UTF-8"));
			String line;
			while ((line = in.readLine()) != null) {
				sb.append(line);
			}
			in.close();
		} catch (ProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(sb.toString());
	}
}
